<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
        <li class="fa fa-remove"></li>
    </button>
    <h5 class="modal-title"></h5>
</div>

<div class="modal-body">
    <form id="module_form" name="module_form" class="form-horizontal">
        <input type="hidden" name="id" id="modelId">
        <input type="hidden" name="revision">
        <!--lastUpdateTime-->
        <input type="hidden" name="deploymentId">
        <input type="hidden" name="editorSourceValueId">
        <input type="hidden" name="editorSourceExtraValueId">
        <div class="box-body">
            <div class="col-md-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">模型名称<span style="color:red">&nbsp;*</span></label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="name" name="name" placeholder="请填写模型名称">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">模型key<span style="color:red">&nbsp;*</span></label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="key" name="key" placeholder="请填写模型key">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">业务类别<span style="color:red">&nbsp;*</span></label>
                    <div class="col-sm-8">
                        <select name="category" id="category" data-src="/activiti/module/getAll" data-flag="urlSelector"
                                data-placeholder="请选择业务类别" class="form-control select2" data-text="name"
                                data-value="code" style="width:100%"
                                data-blank="true"></select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">模型版本<span style="color:red">&nbsp;*</span></label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="version" name="version" placeholder="请填写模板版本">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">多租户标识</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="tenantId " name="tenantId" placeholder="填写多租户标识">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">描述</label>
                    <div class="col-sm-8">
                        <textarea class="form-control" id="description" name="description" rows="2"
                                  placeholder="请填写模型描述"></textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-footer text-right">
            <button type="button" class="btn btn-default" data-btn-type="cancel" data-dismiss="modal"><i
                    class="fa fa-remove"></i>&nbsp;取消
            </button>
            <button type="submit" class="btn btn-primary" data-btn-type="save"><i class="fa fa-save"></i>&nbsp;保存
            </button>
        <!--    <button type="button" class="btn btn-primary" data-btn-type="test" onclick="test()"><i
                    class="fa fa-save"></i>&nbsp;test
            </button>-->
        </div>
    </form>
</div>
<script>
    var form;
    var id = "${id?default(0)}";
    $(function () {
        //初始化表单
        form = $("#module_form").form({baseEntity: false});
        //数据校验
        $("#module_form").bootstrapValidator({
            message: '请输入有效值',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            submitHandler: function () {
                modals.confirm('确认保存？', function () {
                    var vo = form.getFormSimpleData();
                    //alert(JSON.stringify(vo));
                    ajaxPost(basePath + '/activiti/model/save', vo, function (data) {
                        if (data.success) {
                            /*if (id != "0") {
                             modals.hideWin(winId);
                             moduleTable.reloadRowData(id);
                             } else {*/
                            modals.hideWin(winId);
                            modelTable.reloadRowData(data.data);
                            //}
                        }
                    });
                });
            },
            fields: {
                "name": {
                    validators: {
                        notEmpty: {message: '业务名称不能为空'}
                    }
                },
                "key": {
                    validators: {
                        notEmpty: {message: '业务编码不能为空'},
                        remote: {
                            url: basePath + "/activiti/model/uniquekey",
                            data: function (validator) {
                                return {
                                    key: $('#key').val(),
                                    id: $('#modelId').val()
                                };
                            },
                            message: '该编码已被使用'
                        }
                    }
                },
                "version": {
                    validators: {
                        notEmpty: {message: '模型版本不能为空'},
                        integer: {message: '请填写整数'}
                    }
                },
                "category": {
                    validators: {
                        notEmpty: {message: '业务类别不能为空'}
                    }
                }
            }
        });
        //初始化控件
        form.initComponent();
        //编辑回填
        if (id != 0) {
            ajaxPost(basePath + "/activiti/model/get/" + id, null, function (data) {
                form.initFormData(data);
                if(data.description)
                $("#description").val(data.description.replaceAll('"',''));
            })
        }

    });

    function test() {
        var param = form.getFormSimpleData();
        console.log(param);
        alert(typeof param);
        param = {
            id: null,
            revision: null,
            deploymentId: null,
            editorSourceValueId: null,
            editorSourceExtraValueId: null,
            name: "1",
            key: null,
            category: "null",
            version: "1",
            tenantId: null
        },
        ajaxPost(basePath + "/activiti/model/test", param, function (data) {
            modals.correct("测试成功");
        })
    }

</script>
